import pytest
import requests
from unittest.mock import MagicMock, patch

import responses

from appAccounts.services.serviceCustomerWS import do_check_customer

@pytest.mark.withmock
def test_do_check_customer():
    mock_get = MagicMock(spec=requests.Response)
    mock_get.status_code = 200
    mock_get.text = {'status': 'NOT OK'}

    print(f"text ={mock_get.text}")
    print(f"callcnt={mock_get.call_count}")
    print(f"called={mock_get.assert_called}")

    with patch('requests.request', mock_get):
        response = do_check_customer(1, '')

    print(f"call_cnt={mock_get.call_count}")
    print(f"call_args={mock_get.call_args}")

    assert response == True
    assert mock_get.assert_called

    #assert response.json() == mock_data

@pytest.mark.pure
def test_do_check_customer_witout_mock():
    test_cust_id = "1869eb93-5aba-4e1c-a8cc-a4b7a2f4f136"
    mytok="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqbTIyMzRAYmFuay5jb20iLCJwaG9uZSI6InA5MzY3Nzc1NzYzIiwiY3VzdGlkIjoiMTg2OWViOTMtNWFiYS00ZTFjLWE4Y2MtYTRiN2EyZjRmMTM2IiwiZXhwIjoxNzExMjc0MzM0fQ.r0ipJsQG_4BD57sonTwLNyO6_uvAYMxol_6uGkBgJnw"

    mock_get = MagicMock(spec=requests.Response)

    print(f"text ={mock_get.text}")
    print(f"callcnt={mock_get.call_count}")
    print(f"called={mock_get.assert_called}")

    response = do_check_customer(test_cust_id, mytok)

    print(f"call_cnt={mock_get.call_count}")
    print(f"call_args={mock_get.call_args}")

    assert response == True